package com.yc.chaoshi.cs_manage.service.impl;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yc.chaoshi.cs_manage.DTO.OrderDTO;

import com.yc.chaoshi.cs_manage.mapper.OmsOrderMapper;
import com.yc.chaoshi.cs_manage.service.IOmsOrderService;
import com.yc.chaoshi.cs_manage.service.IUmsAddressService;
import com.yc.chaoshi.entity.OmsOrder;
import com.yc.chaoshi.entity.PmsGoods;
import com.yc.chaoshi.entity.UmsAddres;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xz
 * @since 2022-08-04
 */
@Service
public class OmsOrderServiceImpl extends ServiceImpl<OmsOrderMapper, OmsOrder> implements IOmsOrderService {
    @Resource
    IUmsAddressService umsAddressService;
    /**
     * 获得所有订单
     * @param pageNum
     * @param pageSize
     * @param sreachname
     * @param orderstatus
     * @return
     */
    @Override
    public Page listAll(Integer pageNum, Integer pageSize, String sreachname, Integer orderstatus) {
        Page<OrderDTO> page=new Page<>(pageNum,pageSize);
        pageNum=pageSize*(pageNum-1);
        List<OrderDTO> list=baseMapper.listAll(pageNum,pageSize,sreachname,orderstatus);
        long total=baseMapper.listAll(0,10000,sreachname,orderstatus).size();
        page.setRecords(list);
        page.setTotal(total);
        return page;
    }

    @Override
    public boolean delete(Integer id) {
        UpdateWrapper<OmsOrder> updateWrapper=new UpdateWrapper<>();
        updateWrapper.lambda().eq(OmsOrder::getId,id)
                              .set(OmsOrder::getStatus,0);
        return  this.update(updateWrapper);
    }

    @Override
    public UmsAddres getaddress(Integer addressid) {
        return umsAddressService.getById(addressid);
    }

    @Override
    public Page listGoods(Integer pageNum, Integer pageSize, String sreachname, Integer orderid) {
        Page<PmsGoods> page=new Page<>(pageNum,pageSize);
        pageNum=pageSize*(pageNum-1);
        List<PmsGoods> list=baseMapper.listGoods(pageNum,pageSize,sreachname,orderid);
        long total=baseMapper.listGoods(0,10000,sreachname,orderid).size();
        page.setRecords(list);
        page.setTotal(total);
        return page;
    }

}
